import { Component } from '@angular/core';
import { NavController, NavParams, ModalController, LoadingController } from 'ionic-angular';
import { BaseUI } from '../../common/baseui';
import { RestProvider } from '../../providers/rest/rest';
import { DetailsPage } from '../details/details';

/**
 * Generated class for the DiscoveryPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */


@Component({
  selector: 'page-discovery',
  templateUrl: 'discovery.html',
})
export class DiscoveryPage extends BaseUI {
  questions: any = [];
  errMessage: string;
  constructor(
    public navCtrl: NavController,
    private modalCtrl: ModalController,
    private rest: RestProvider,
    private loadingCtrl: LoadingController) {
    super();
  }
  ngOnInit() {
    this.getQuestion();
  }
  ionViewDidLoad() {

  }
  getQuestion() {
    var loading = super.showLoading(this.loadingCtrl, "加载中...")
    this.rest.getQuestions()
      .subscribe(data => {
        this.questions = data;
        loading.dismiss();
      }, error => this.errMessage = <any>error);
  }
  goDetail(id) {
    this.navCtrl.push(DetailsPage, {
      id: id
    });
  }
  doRefresh(refresher) {
    this.getQuestion();
    refresher.complete();
  }
}
